The example Code

The file main.c contains all of the non-OOGL code. The routine myfunc is the function to be computed over the mesh. Its arguments are the x and y location on the mesh and the time since the start of the program.

The main routine first performs a number of initialization steps. The call to Begin_OOGL essentially creates an empty geometry template and returns:

fprintf(f, "(geometry example { : exhandle })\n");
fflush(f);

This notifies the viewer to create an object known as example. It gives it the internal name, or handle, exhandle. More on this later when we come to UpdateOOGL

After initializing everything, main enters an endless loop where it computes the values of the function over each point in the mesh and then calls UpdateOOGL to update the OOGL mesh in shared memory. User interface allows the user to change the value of dt. The resulting data array and other parameters are passed to UpdateOOGL.

UpdateOOGL's main task is to create a Mesh object from the data which has been passed in. This is the one slightly tricky section of the program, since the particular features of each subclass must be known in order to create an instance.

All the Create routines are accessed through the generic GeomCreate routine. The first parameter is an ascii string identifying the subclass, in this case "mesh". From then on, the Create routine expects a sequence of keys accompanied with optional key values. A complete list of these keys is given in GEOM/include/create.h. There are a number of generic sorts of keys, such as CR_NOCOPY or CR_POINT, which are valid for any subclass. CR_NOCOPY tells the create routines to use the data you have provided without copying it over – so we are careful not to delete the data storage we are passing. CR_POINT identifies an array of 3-dimensional vertices; CR_POINT4 does the same for 4-dimensional vertices.

Other of these keys, however, are specific to the Mesh subclass. For example, CR_NU and CR_NV specify the dimensions of the mesh. Last and most difficult, CR_FLAG identifies a set of flag values which vary with each subclass and can only be fully learned by consulting the specific subclass.h file. In this case, we consult meshflag.h to find that we must use the MESH_Z flag for our data, since we aren't providing explicit (x,y) data with the z-values.

The best way to become comfortable with this aspect of the Create routines is to examine other examples in the GEOM/src/bin directory, and explore the include files corresponding to your favorite subclass.

GeomCreate returns a pointer to a Geom upon successful completion. It also happens to be a pointer to a Mesh, but we don't care any more what kind of Geom it is.

The final step is to put this mesh out onto the pipe. We do this by wrapping a call to GeomFSave within a simple command which connects this geometry to the afore-mentioned handle exhandle. GeomFSave prints onto the given file stream, in this case, standard output, the value of the Geom. Then, when geomview reads this stream, it will redefine exhandle to replace any old definitions.